label: Add ink rect support to GtkLabel
authorBenjamin Otte <otte@redhat.com>
Thu, 10 Jul 2014 16:31:15 +0000 (18:31 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 10 Jul 2014 16:56:34 +0000 (18:56 +0200)
gtk/gtklabel.c

index 9cc6ff92a9099b94af958d29c91e24fae61e7cd3..b3fd1537a098d4fd86d09c682c5edf2954747092 100644 (file)
@@ -3955,12 +3955,31 @@ G_GNUC_END_IGNORE_DEPRECATIONS
     *yp = y;
 }
 
+static void
+gtk_label_get_ink_rect (GtkLabel     *label,
+                        GdkRectangle *rect)
+{
+  GtkLabelPrivate *priv = label->priv;
+  PangoRectangle ink_rect;
+  int x, y;
+
+  gtk_label_ensure_layout (label);
+  get_layout_location (label, &x, &y);
+  pango_layout_get_pixel_extents (priv->layout, &ink_rect, NULL);
+
+  rect->x = x + ink_rect.x;
+  rect->width = ink_rect.width;
+  rect->y = y + ink_rect.y;
+  rect->height = ink_rect.height;
+}
+
 static void
 gtk_label_size_allocate (GtkWidget     *widget,
                          GtkAllocation *allocation)
 {
   GtkLabel *label = GTK_LABEL (widget);
   GtkLabelPrivate *priv = label->priv;
+  GdkRectangle clip_rect;
 
   GTK_WIDGET_CLASS (gtk_label_parent_class)->size_allocate (widget, allocation);
 
@@ -3975,6 +3994,9 @@ gtk_label_size_allocate (GtkWidget     *widget,
                               allocation->width,
                               allocation->height);
     }
+
+  gtk_label_get_ink_rect (label, &clip_rect);
+  gtk_widget_set_clip (widget, &clip_rect);
 }
 
 static void